// pages/questionnaire/questionnaire.js
const { getStuQuestionnaire, getStuTeacher } = require('../../api/geData.js')
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    quesSurveyList: [],
    teacherSurveyList:[],
    currentTab: 0,
  },
  toDetail(e){
    // console.log(e.currentTarget.dataset.id)
    let data = this.data.quesSurveyList.filter(item=>{
      
      if (item.id == e.currentTarget.dataset.pid){
        return item
      }
    })
    let status = '';
    // console.log(data)
    if (data[0].isReply!='0'){
      //已回复
      wx.navigateTo({
        url: '/pages/questionnaire/detailDone?pid=' + e.currentTarget.dataset.pid + '&id=' + e.currentTarget.dataset.id
      })
      return;
    } else if (data[0].questionnaireState == '0'){
      //未完成
      status = '0'
    }else{
      //已撤回
      status = '2'
    }
    wx.navigateTo({
      url: '/pages/questionnaire/detail?pid=' + e.currentTarget.dataset.pid + '&id=' + e.currentTarget.dataset.id + '&status=' + status
    })
  },
  toConcludingDetail(e){
    console.log(e.currentTarget.dataset.item)
    let data = e.currentTarget.dataset.item,
        status=7;
    wx.setStorageSync('sevenData', {
      status: status,
      coursename: data.course_name
    })
    if (data.is_reply != '1') {
      wx.navigateTo({
        url: `/pages/questionSurvey/questionSurvey?stuId=${data.student_id}&formalClassId=${data.formal_class_id}`
      })
    } else {
      wx.navigateTo({
        url: `/pages/detail/detailGrade/detailGrade?status=${status}&coursename=${data.course_name}`
      })
    }
  },
  switchquestionnaireTab(e){
    let that = this;
    if (this.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentTab: e.target.dataset.current,
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let user = wx.getStorageSync('userInfo')
    if (user) {
      getStuQuestionnaire(user.cluesOrStuId).then(res => {
        this.setData({
          quesSurveyList: res.quesSurveyList
        })
        // console.log(this.data.quesSurveyList)
      })
      getStuTeacher(user.cluesOrStuId).then(res=>{
        console.log(res)
        this.setData({
          teacherSurveyList: res.quesSurveyList
        })
      })
    } else {
      // console.log('无学生')
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})